<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <!-- 不遵从单向数据流原则 -->
    <div id="app">
        <li v-for="(item,index) in parr">{{item}}</li>
        <hr />
        <menu-item :title='parr'></menu-item>
    </div>

    <script src="../../js/vue.js"></script>
    <script>
        Vue.component("menu-item", {
            data() {
                return {
                    msg: '子组件本身的数据'
                }
            },
            props: ['title'],
            template: `
                <div>
                    <span>~~~</span>
                    <li v-for="(item,index) in title">{{item}}</li>
                    <button @click='title.push("hello")'>新增</button>
                </div>
            `
        })
        var vm = new Vue({
            el: '#app',
            data: {
                parr: ["www", "org"]
            }
        })
    </script>



    <!-- 遵从数据传递原则 -->
    <!-- <button v-on:click="$emit('enlarge-text)'">扩大文本</button>
    <menu-item v-on:enlarge-text="handleFunction"></menu-item> -->
    <hr></hr>
    <hr></hr>
    <hr></hr>
    <div id="app2">
        <div :style="{fontSize: fontSize + 'px'}">扩大文本</div>
        <menu-item2 v-on:enlarge-text="handleFunction($event, $event)"></menu-item>
    </div>
    <script>
        Vue.component("menu-item2", {
            props: ['title'],
            template: `
                <div>
                    <span>~~~</span>
                    <button v-on:click="$emit('enlarge-text', 5, 55)">扩大父组件中字体大小</button>
                    <button v-on:click="$emit('enlarge-text', 10, 100)">扩大父组件中字体大小</button>
                </div>
            `
        })
        var vm2 = new Vue({
            el: '#app2',
            data: {
                fontSize: 10
            },
            methods: {
                handleFunction(val, value2){
                    console.log('val--', val, value2)
                    this.fontSize += val
                }
            }
        })
    </script>



</body>

</html>